#-*- coding: utf-8 -*-

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from models import Account
from kombu.transport.django import models as kombu_models


class AccountAdmin(admin.ModelAdmin):

    list_display = ('id', 'user', 'phone', 'nickname', 'truename', 'avatar', 'is_valid', 'last_login')
    readonly_fields = ('id', 'user', 'phone', 'nickname', 'truename', 'is_valid', 'last_login')
    def has_add_permission(self, request):
        return False

class AccountInline(admin.StackedInline):
    model = Account


class UserAccuntAdmin(UserAdmin):
    inlines = [AccountInline, ]
    list_display = ('id', 'username', 'phone', 'email', 'nickname', 'truename', 'active_token', 'is_valid',
                    'is_active', 'is_staff', 'last_login', 'date_joined' )
    list_display_links = ('id', 'phone', 'email')
    search_fields = ['account__phone', 'email']

    def phone(self, obj):
        return '%s' % obj.account.phone
    phone.short_description = u'手机号'

    def nickname(self, obj):
        return '%s' % obj.account.nickname
    nickname.short_description = u'昵称'

    def truename(self, obj):
        return '%s' % obj.account.truename
    truename.short_description = u'实名'

    def active_token(self, obj):
        return '%s' % obj.account.active_token
    active_token.short_description = u'验证token'

    def is_valid(self, obj):
        return '%s' % obj.account.is_valid
    is_valid.short_description = u'是否否验证'

    def last_login(self, obj):
        return '%s' % obj.account.last_login
    last_login.short_description = u'最后登录时间'


admin.site.unregister(User)
admin.site.register(User, UserAccuntAdmin)
admin.site.register(Account, AccountAdmin)
admin.site.register(kombu_models.Message)